package com.example.tool.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;

import com.example.tool.R;

/**
 * 项目中使用的数字字体
 * Created by asus on 2018/3/28.
 */

public class NumTextView extends android.support.v7.widget.AppCompatTextView {
    private boolean isBold = true;

    public NumTextView(Context context) {
        super(context);
        init(context,null);
    }

    public NumTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    public NumTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }

    @SuppressLint("CustomViewStyleable")
    private void init(Context context, AttributeSet attrs) {
        TypedArray attributes = null;
        if (attrs != null){
            attributes = context.obtainStyledAttributes(attrs, R.styleable.NumTextType);
            isBold = attributes.getBoolean(R.styleable.NumTextType_bold,true);
            attributes.recycle();
        }

        Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/DINOT-CONDMEDIUM.OTF");
        if (isBold){
            getPaint().setFakeBoldText(true);

        }

        setTypeface(font);

    }
}
